package com.jyw.web.controller.system;

import com.jyw.common.annotation.Log;
import com.jyw.common.core.domain.CommonResult;
import com.jyw.common.enums.BusinessType;
import com.jyw.system.domain.vo.SysOrderExpectedTimeConfigVo;
import com.jyw.system.service.ISysOrderExpectedTimeConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.time.LocalDateTime;

/**
 * @author Created by ZhangCheng on 2023/01/11 (系统工单期望完成时间配置)
 */
@Api(tags = "系统工单期望完成时间配置")
@RestController
@RequestMapping("/system/orderExpectedTimeConfig")
public class SysOrderExpectedTimeConfigController {

    @Resource
    private ISysOrderExpectedTimeConfigService sysOrderExpectedTimeConfigService;

    /**
     * 获取系统工单期望完成时间配置
     *
     * @return
     */
    @GetMapping("/getConfig")
    @ApiOperation("获取系统工单期望完成时间配置")
    public CommonResult<SysOrderExpectedTimeConfigVo> getConfig() {
        return CommonResult.success(sysOrderExpectedTimeConfigService.getDefaultConfig());
    }

    /**
     * 修改系统工单期望完成时间配置
     *
     * @param sysOrderExpectedTimeConfigVo
     * @return
     */
    @Log(title = "修改系统工单期望完成时间配置", businessType = BusinessType.UPDATE)
    @PutMapping("/updateConfig")
    @ApiOperation("修改系统工单期望完成时间配置")
    public CommonResult updateConfig(@RequestBody @Valid SysOrderExpectedTimeConfigVo sysOrderExpectedTimeConfigVo) {
        sysOrderExpectedTimeConfigService.updateConfig(sysOrderExpectedTimeConfigVo);
        return CommonResult.success();
    }

    /**
     * 获取期望完成时间类型
     *
     * @return
     */
    @GetMapping("/getExpectedTimeType")
    @ApiOperation("获取期望完成时间类型")
    public CommonResult<Integer> getExpectedTimeType() {
        LocalDateTime now=LocalDateTime.now();
        return CommonResult.success(sysOrderExpectedTimeConfigService.getExpectedTimeType(now));
    }
}
